/**
 * Created by Brant on 2016/12/28.
 */
module.exports = function ($rootScope, $scope, $stateParams, $filter, caseBarDetailxiaService, $cookies, $state,caseBarDetailBarService,customerBarService) {

    var expireDate = new Date();
    expireDate.setDate(expireDate.getDate() + 1);

    $scope.navcasebusinessname = $cookies.get('navcasebusinessname');
    $scope.navcasecausename = $cookies.get('navcasecausename');
    $scope.type = $cookies.get('type');


    /*登录ID*/
    $scope.loginId = kbt.decrypt($cookies.get('cookieUserId'));
    //用户名
    var loginName = kbt.decrypt($cookies.get('cookieUserName'));


    //获取点击的案件的id
    var caseId = $cookies.get('caseAppId');
    // 案件名字
    var caseName = $cookies.get("caseAppName");
    $scope.type1 = "";

    //获取当事人
    $scope.dsrList = '';
    $scope.dsrcasetype = '';


    //获取对方当事人
    $scope.dfdsrList = '';
    $scope.dfdsrcasetype = '';


    //当事人,个人的搜索框
    $scope.searchPeoInput = '';
    //当事人法人,个人搜索
    $scope.searchCusInput = '';
    //原告添加--自然人名称、手机号
    // $scope.addNaturalPerCase.name = '';
    // $scope.addNaturalPerCase.contactnumber = '';
    // 原告添加--机构名称、法人名称、法人手机号
    // $scope.addOrganizaCase.companyname = '';
    // $scope.addDSRComPerInput = '';
    // $scope.addOrganizaCase.contactphone = '';

    //添加被告
    $scope.addDFDSRInput = '';

    $scope.keyword = '';

    //省市区,法院
    $scope.provinceName = '';
    $scope.cityName = '';
    $scope.districtName = '';
    $scope.courtName = '';

    $scope.provinces = '';
    $scope.cities = '';
    $scope.districts = '';
    $scope.courts = '';

    //设置一个json字符串 请求的时候需要传过去
    $scope.casejson = "";

    //手机号
    $scope.cellphone = '';
    //律师区分类别
    var caselvshitype = 3;


    /**律师成员的集合页面获取的*/
    var lawyersbarrister = new Array();

    /**律师成员的集合*/
    var lawyers = new Array();

    /**律师成员的判断条件*/
    var lawyersflost = true;

    /**律师接口*/
    var CaseLawyersList = [];

    //监听广播，父类请求数据后刷新案件详情
    $scope.$on('refreshCaseDetail', function (event, data) {
      //刷新初始化
      $scope.getCaseDetails(data);
    });

    $scope.init = function () {
        $scope.hideArchive();

        /*用于固定导航条*/
        sessionStorage.navNum = 0;
    };

    /**
     * 案件进度相关
     */
    $scope.caseProgress = {
        caseProgress: '',//进度百分比
        delayTask: '',//延误任务
        finishedTask: '',//已完成任务
        totalTask: '',//总任务
        unFinishedTask: ''//未完成任务
    };

    /**
     * 案件相关
     */
    $scope.case = {
        //诉讼请求
        demand: '',
        //案件概述
        summary: '',
        //审理程序
        caseBusiness: {
            casebusinessname: ''
        },
        //案件类型
        caseClassification: {
            caseclassificationname: ''
        },
        //案件类别
        caseType: {
            casetypename: ''
        },
        //案由
        casecause: {
            casecausename: ''
        },
        //审理法院
        court: {
            courtprovice: '',//省
            courtcity: '',//市
            courtdistict: '',//区
            courtname: ''//法院名字
        }
    };

    // 阻止输出log
    // wangEditor.config.printLog = false;
    // var editor = new wangEditor('mCaseCompile');
    // var editor2 = new wangEditor('mCaseLawsuit');
    //编辑输入
    // jQuery(function ($) {
    //
    //     // editor.config.menus = $.map(wangEditor.config.menus, function(item, key) {
    //     //     if (item === 'insertcode') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'fullscreen') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'img') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'video') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'location') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'link') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'unlink') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'table') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'emotion') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'bgcolor') {
    //     //         return null;
    //     //     }
    //     //
    //     //     return item;
    //     // });
    //     // 配置 onchange 事件
    //     editor.onchange = function () {
    //         var TextCaseLawsuit=this.$txt.text();
    //         var htmlCaseLawsuit=this.$txt.html();
    //         // 编辑区域内容变化时，实时打印出当前内容
    //         var len= strlen(TextCaseLawsuit);
    //         if(len<201){
    //             $("#mCaseCompileText").html("<b>还剩下<b style='color: red'>"+(200-len)+"</b>字可</b>");
    //
    //         } else{
    //           $("#mCaseCompileText").html("<b style='color: red'>诉讼请求要求200字以内，您已超出"+(len-200)+"字!</b>");
    //             //只能输入两百个字
    //             //this.$txt.html(TextCaseLawsuit.Substring(0,TextCaseLawsuit.Length-(len-200)));
    //           // this.$txt.html(htmlCaseLawsuit.substring(0,200));
    //        }
    //
    //     };
    //     editor.create();
    //
    //
    //
    //     // editor2.config.menus = $.map(wangEditor.config.menus, function(item, key) {
    //     //     if (item === 'insertcode') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'fullscreen') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'img') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'video') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'location') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'link') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'unlink') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'table') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'emotion') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'bgcolor') {
    //     //         return null;
    //     //     }
    //     //     return item;
    //     // })        // editor2.config.menus = $.map(wangEditor.config.menus, function(item, key) {
    //     //     if (item === 'insertcode') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'fullscreen') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'img') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'video') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'location') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'link') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'unlink') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'table') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'emotion') {
    //     //         return null;
    //     //     }
    //     //     if (item === 'bgcolor') {
    //     //         return null;
    //     //     }
    //     //     return item;
    //     // });
    //     // 配置 onchange 事件
    //     editor2.onchange = function () {
    //         var TextCaseLawsuit=this.$txt.text();
    //         var htmlCaseLawsuit=this.$txt.html();
    //         // 编辑区域内容变化时，实时打印出当前内容
    //         var len= strlen(TextCaseLawsuit);
    //         if(len<201){
    //             $("#mCaseLawsuitText").html("<b>还剩下<b style='color: red'>"+(200-len)+"</b>字可</b>");
    //         }
    //        else{
    //             $("#mCaseLawsuitText").html("<b style='color: red'>诉讼请求要求200字以内，您已超出"+(len-200)+"字!</b>");
    //             //只能输入两百个字
    //             //this.$txt.html(TextCaseLawsuit.Substring(0,TextCaseLawsuit.Length-(len-200)));
    //           //  this.$txt.html(htmlCaseLawsuit.substring(0,200));
    //         }
    //
    //     };
    //
    //     editor2.create();
    // });

    /**判断字符串长度*/
    function strlen(str){
        var len = 0;
        for (var i=0; i<str.length; i++) {
            var c = str.charCodeAt(i);
            //单字节加1
            if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {
                len++;
            }
            else {
                len+=2;
            }
        }
        return len;
    }


    /**
     * 归档案件不能添加律师成员
     */
    $(".addlvshi").on("click", function () {
        if ($rootScope.typeIf==7) {
            $(".addlvshi").attr("disabled", "disabled");//主办律师
        } else {
            $(".LawyerAddBody-xia").removeClass("hide");
        }
    });


    //获取当事人列表
    $scope.getDSRList = function (caseId) {
        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;
        caseBarDetailxiaService.getDSRList(caseId).then(function (data) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            if (data.code == 1) {
                $scope.dsrList = data.data;

                for (var i = 0; i < data.data.length; i++) {

                    $scope.dsrList[i].dsrtextmm=true;

                    $scope.dsrcasetype = data.data[i].casetype;
                    if ($scope.dsrcasetype == 1) {
                        $scope.dsrcasetype = '原告';
                    } else {
                        $scope.dsrcasetype = '被告';
                    }
                }

            } else {

            }
        });
    };
    // $scope.getDSRList(caseId);

    //添加当事人->个人
    $scope.addDSRAppleS = function (name,id) {
        var caseType = 1;
        if ($scope.dsrcasetype == '原告') {
            caseType = 1;
        } else {
            caseType = 3;
        }
        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;
        //还得修改
        caseBarDetailxiaService.addDSR(caseId, caseType, 1, name, id,$scope.loginId).then(function (data) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            if (data.code == 1) {
                //获取当事人列表
                $scope.getDSRList(caseId);
                $('.L_peplAddBox2').addClass('hide');
                $scope.addNaturalPerCase = {};
                $scope.searchPeoInput = '';
                $scope.zusers = '';
                $scope.fusers = '';
            }
        });
    };
    //添加当事人->个人
    $scope.addDSRAppleI = function () {
        if ($scope.addNaturalPerCase.contactnumber != '') {
            var caseType = 1;
            if ($scope.dsrcasetype == '原告') {
                caseType = 1;
            } else {
                caseType = 3;
            }
            $rootScope.loadingShow = true;
            $rootScope.fadeShow = true;
            caseBarDetailxiaService.addDSR(caseId, caseType, 1, $scope.addNaturalPerCase.contactnumber, $scope.loginId).then(function (data) {
                $rootScope.loadingShow = false;
                $rootScope.fadeShow = false;
                if (data.code == 1) {
                    //获取当事人列表
                    $scope.getDSRList(caseId);
                    $('.L_peplAddBox2').addClass('hide');
                }
            });
            //添加到客户版
            caseBarDetailxiaService.addZRRCustomer($scope.loginId, $scope.addNaturalPerCase.contactnumber, null, null, null, null, null, null, null, null, null).then(function (data) {
            });
        }
    };
    //添加当事人->公司
    $scope.addDSRComS = function (name,id) {
        var caseType = 1;
        if ($scope.dsrcasetype == '原告') {
            caseType = 1;
        } else {
            caseType = 3;
        }
        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;
        //还得修改
        caseBarDetailxiaService.addDSR(caseId, caseType, 3, name, id,$scope.loginId).then(function (data) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            if (data.code == 1) {
                //获取当事人列表
                $scope.getDSRList(caseId);
                $('.peplAddBox2').addClass('hide');
                $scope.addOrganizaCase = {};
            }
        });
    };
    //添加当事人->公司
    $scope.addDSRComI = function () {
        if ($scope.addOrganizaCase.companyname != '') {
            var caseType = 1;
            if ($scope.dsrcasetype == '原告') {
                caseType = 1;
            } else {
                caseType = 3;
            }
            $rootScope.loadingShow = true;
            $rootScope.fadeShow = true;
            caseBarDetailxiaService.addDSR(caseId, caseType, 3, $scope.addOrganizaCase.companyname, $scope.loginId).then(function (data) {
                $rootScope.loadingShow = false;
                $rootScope.fadeShow = false;
                if (data.code == 1) {
                    //获取当事人列表
                    $scope.getDSRList(caseId);
                    $('.peplAddBox2').addClass('hide');

                }
            });
            //添加到客户版
            caseBarDetailxiaService.addFRCustomer($scope.loginId, $scope.addOrganizaCase.companyname, null, null, null, null, null, null, null, null).then(function (data) {

            });
        }
    };


    //获取对方当事人列表
    $scope.getDFDSRList = function (caseId) {
        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;
        caseBarDetailxiaService.getDFDSRList(caseId).then(function (data) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            if (data.code == 1) {
                $scope.dfdsrList = data.data;

                for (var i = 0; i < data.data.length; i++) {
                    $scope.dfdsrList[i].dfdsrtextmm=true;
                    $scope.dfdsrcasetype = data.data[i].casetype;
                    if ($scope.dfdsrcasetype == 1) {
                        $scope.dfdsrcasetype = '原告';
                    } else {
                        $scope.dfdsrcasetype = '被告';
                    }
                }

            } else if(data.code==0 && data.message=='无对方当事人！'){
                $scope.dfdsrList = "";
            }
        });
    };
    // $scope.getDFDSRList(caseId);


    //添加对方当事人
    $scope.addDFDSR = function () {
        if ($scope.addDFDSRInput != '') {
            var caseType = 1;
            if ($scope.dfdsrcasetype == 1) {
                caseType = 1;
            } else {
                caseType = 3;
            }
            $rootScope.loadingShow = true;
            $rootScope.fadeShow = true;
            caseBarDetailxiaService.addDFDSR(caseId, caseType, '', $scope.addDFDSRInput, $scope.loginId).then(function (data) {
                $rootScope.loadingShow = false;
                $rootScope.fadeShow = false;
                if (data.code == 1) {
                    $scope.getDFDSRList(caseId);
                    $('.L_peplAddBox').addClass('hide');
                    $scope.addDFDSRInput = '';
                }
            });
        }
    };
    //添加对方当事人--关闭
    $(".Add-close").on("click", function () {
      $(this).parent(".L_peplAddBox2").addClass("hide");
      $scope.searchPeoInput = '';
      $scope.addNaturalPerCase.contactnumber = '';
    });
    //添加对方当事人--取消
    $(".Add-cancel").on("click", function () {
      $(".L_peplAddBox2").addClass("hide");
    });

    //form-control  ng-pristine ng-untouched ng-valid
    //获取自然人
    $scope.mParties = function () {
        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;
        caseBarDetailxiaService.selectZiRanRenInfo($scope.loginId, null, null, $scope.searchPeoInput).then(function (data) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            if (data.code == 1) {
                $scope.zusers = data.data;
            }
        }, function () {
        });


    };
    //获取公司法人
    $scope.mParties2 = function () {

        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;
        caseBarDetailxiaService.selectFaRenInfo($scope.loginId, 100000, 1, $scope.searchCusInput).then(function (data) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            if (data.code == 1) {
                $scope.fusers = data.data.list;
            }
        }, function () {

        });

        /* $(document).keyup(function (event) {
         //获取公司的法人列表
         if (event.keyCode == 13 && $('.peplAddBox2').css('display') == 'block' && $('.cuseplAddDivliIn').css('display') == 'block') {
         $rootScope.loadingShow = true;
         $rootScope.fadeShow = true;
         caseBarDetailxiaService.selectFaRenInfo($scope.loginId, 100000, 1, $scope.searchCusInput).then(function (data) {
         $rootScope.loadingShow = false;
         $rootScope.fadeShow = false;
         if (data.code == 1) {
         $scope.fusers = data.data.list;
         }
         }, function () {
         });

         }
         });*/

    };
    //获取律师
    $scope.mParties3 = function () {
        $(document).keyup(function (event) {
            //查询律师成员接口
            if (event.keyCode == 13) {
                if ($scope.keyword != '') {
                    $rootScope.loadingShow = true;
                    $rootScope.fadeShow = true;
                    caseBarDetailxiaService.CaseLawyerTian($scope.keyword).then(function (data) {
                        $('.LawyerboxUl').show();
                        $('.LawyerboxUl').css("height", "100px");
                        $('.LawyerAddBody-xia').css("min-height", "230px");
                        if (data.code == 1) {
                            setbarristername(data);
                        } else {
                            $(".LawyerboxUlS").html("请检查输入是否正确");
                            $(".LawyerboxUlbutton").hide()
                        }
                        $rootScope.loadingShow = false;
                        $rootScope.fadeShow = false;

                    }, function () {
                        $rootScope.loadingShow = false;
                        $rootScope.fadeShow = false;
                    });
                }
            }
        });
    };


    /**添加律师成员*/
    function setbarristername(data) {
        //列表
        $scope.CaseLawyerTianSelect = data.data;


        //修改律师
        $scope.CaseLawyerTianButton = function (name, LawyerId) {
            $scope.CaseLawyerTianModel = name;
            $scope.LawyerId = LawyerId;
            if (caselvshitype == 1) {
                //去除律师
                dislodgehostLawyer(lawyersbarrister, 1);
            }
            if (caselvshitype == 2) {
                //去除律师
                dislodgehostLawyer(lawyersbarrister, 2);
            }
            if (caselvshitype == 3) {
            }

            var hostLawyer = new Object();
            //  hostLawyer.id = null;
            hostLawyer.lawyerId = LawyerId;
            hostLawyer.lawyerType = parseInt(caselvshitype);
            lawyersbarrister.push(hostLawyer);
            //修改律师
            modification($scope.CaseLawyerTianModel, $scope.LawyerId);

            $(".addlvshi").on("click", function () {

                $(".LawyerAddBody-xia").show();
            });
            $(".LawyerAddBody-xia").hide();
            $scope.keyword = '';
        };

        //点击关闭
        $scope.CaseLawyerClose = function () {
            $scope.CaseLawyerTianModel = "";
        };

        $(".LawyerboxUlbutton").show()
    }

var courtId = 0;
    //法院
    $scope.getCourtList = function () {
      var courtname = "";
      if(typeof($scope.case.court) == 'string') {
        courtname = $scope.case.court;
      } else {
        courtname = $scope.case.court.courtname;
      }
      if (courtname && courtname.length >= 2) {
            var params = {"courtName":courtname, "type":3};
            caseBarDetailxiaService.getCourtList(params).then(function (data) {
                if (data.code == 1) {
                    $scope.courts = data.data.courts;
                }
            });
        }
    };

    //案件信息模块
    //点击案件编辑
    $('.ajclickBJ').click(function () {
        // 初始化编辑器的内容
        editor.$txt.html($scope.case.summary);

        $("#mCaseCompileText").show();

        $(this).parents('.ajBJFather').siblings('.ajtextBox').addClass('hide');
        $(this).parents('.ajBJFather').siblings('.ajtextareaAndSaveBox').removeClass('hide');

        //案件概述编辑消失
      $('#ajclickBJ').css("display",'none');
    });
    //案件编辑取消
    $('.ajCancelBtn').click(function () {
        $("#mCaseCompileText").hide();
        $(this).parents('.ajtextareaAndSaveBox').siblings('.ajtextBox').removeClass('hide');
        $(this).parents('.ajtextareaAndSaveBox').addClass('hide');
        $('#ajclickBJ').css('display','block');
    });
    //点击诉讼编辑
    $('.ssclickBJ').click(function () {

        // 初始化编辑器的内容
        editor2.$txt.html($scope.case.demand);

        $("#mCaseLawsuitText").show();

        $(this).parents('.ssBJFather').siblings('.sstextBox').addClass('hide');
        $(this).parents('.ssBJFather').siblings('.sstextareaAndSaveBox').removeClass('hide');

        //诉讼编辑消失
        $('#ssclickBJ').css('display','none');
    });
    //诉讼编辑取消
    $('.ssCancelBtn').click(function () {
        $("#mCaseLawsuitText").hide();
        $(this).parents('.sstextareaAndSaveBox').siblings('.sstextBox').removeClass('hide');
        $(this).parents('.sstextareaAndSaveBox').addClass('hide');
        //诉讼编辑显示
        $('#ssclickBJ').css('display','block');
    });

    /**
     * 获取案件详情信息接口
     * 案件进度、类型、类别、审理程序、案由、审理法院
     */
    $rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {
        $rootScope.previousState = from;
    });

    $scope.caseLawyers = [];
    $scope.getCaseDetails = function (data) {
        CaseLawyersList = [];
        /*判断案件ID不能为空*/
        if (caseId != null && caseId != undefined && caseId != "") {

          if (data != undefined) {
            if (data.code == 1) {


              $scope.caseProgress = data.data.caseProgress;
              $scope.case = data.data.case;
              $scope.case.contractEndDate = $filter('date')($scope.case.contractEndDate, 'yyyy-MM-dd');
              $scope.case.contractStartDate = $filter('date')($scope.case.contractStartDate, 'yyyy-MM-dd');
              $scope.caseLawyers = data.data.caseLawyers;
              $scope.source = data.data.caseOriginList;
              $scope.caseJudgesList = data.data.caseJudgesList;
              $scope.caseClients = data.data.caseClients;
              // 业务类型
              $scope.typeFirList = data.data.typeFirList;
              // 委托事项
              $scope.typeSecList = data.data.typeSecList;

              //$scope.


              /*保存案由和审理程序，用于更新标题*/
              if($scope.case.caseBusiness){
                $cookies.put('navcasebusinessname', $scope.case.caseBusiness.casebusinessname, {
                  expires: expireDate
                });//审理程序
              }
              if($scope.case.casecause){
                $cookies.put('navcasecausename', $scope.case.casecause.casecausename, {
                  expires: expireDate
                });//案由
              }

              $('#progress-id').css('width', data.data.caseProgress.caseProgress);
              if ($scope.case.court != null || $scope.case.court == '' || $scope.case.court != undefined) {
                $(".province-text").html($scope.case.court.courtprovice);
                $(".city-text").html($scope.case.court.courtcity);
                $(".district-text").html($scope.case.court.courtdistict);
                $(".court-text").html($scope.case.court.courtname);

                $scope.provinceName = $scope.case.court.courtprovice;
                $scope.cityName = $scope.case.court.courtcity;
                $scope.districtName = $scope.case.court.courtdistict;
                $scope.courtName = $scope.case.court.courtname;
              }
              //取出除律师的参数并且编辑赋值
              barrister(data.data.caseLawyers);
              // 对方当事人
              $scope.dfdsrList = data.data.caseAdversaryClients;

              for (var i = 0; i < $scope.dfdsrList.length; i++) {
                $scope.dfdsrList[i].dfdsrtextmm = true;
                $scope.dfdsrcasetype = $scope.dfdsrList[i].casetype;
                if ($scope.dfdsrcasetype == 1) {
                  $scope.dfdsrcasetype = '原告';
                } else {
                  $scope.dfdsrcasetype = '被告';
                }
              }
              // 当事人
              $scope.dsrList = data.data.caseClients;

              for (var i = 0; i < $scope.dsrList.length; i++) {

                $scope.dsrList[i].dsrtextmm = true;

                $scope.dsrcasetype = $scope.dsrList[i].casetype;
                if ($scope.dsrcasetype == 1) {
                  $scope.dsrcasetype = '原告';
                } else {
                  $scope.dsrcasetype = '被告';
                }
              }
            }
          } else if($rootScope.previousState != undefined && $rootScope.previousState.name != "caseBar"){

            $rootScope.loadingShow = true;
            $rootScope.fadeShow = true;
            caseBarDetailxiaService.getCaseDetails(caseId).then(function (data) {
              if (data.code == 1) {
                $scope.caseProgress = data.data.caseProgress;
                $scope.case = data.data.case;
                $scope.caseLawyers = data.data.caseLawyers;
                $scope.source = data.data.caseOriginList;
                $scope.caseJudgesList = data.data.caseJudgesList;
                $scope.caseClients = data.data.caseClients;
                $scope.case.contractEndDate = $filter('date')($scope.case.contractEndDate, 'yyyy-MM-dd');
                $scope.case.contractStartDate = $filter('date')($scope.case.contractStartDate, 'yyyy-MM-dd');
                /*业务类型*/
                $scope.typeFirList = data.data.typeFirList;
                // 委托事项
                $scope.typeSecList = data.data.typeSecList;

                /*保存案由和审理程序，用于更新标题*/
                if($scope.case.caseBusiness){
                  $cookies.put('navcasebusinessname', $scope.case.caseBusiness.casebusinessname, {
                    expires: expireDate
                  });//审理程序
                }
                if($scope.case.casecause){
                  $cookies.put('navcasecausename', $scope.case.casecause.casecausename, {
                    expires: expireDate
                  });//案由
                }
                $('#progress-id').css('width', data.data.caseProgress.caseProgress);
                if ($scope.case.court != null || $scope.case.court == '' || $scope.case.court != undefined) {
                  $(".province-text").html($scope.case.court.courtprovice);
                  $(".city-text").html($scope.case.court.courtcity);
                  $(".district-text").html($scope.case.court.courtdistict);
                  $(".court-text").html($scope.case.court.courtname);

                  $scope.provinceName = $scope.case.court.courtprovice;
                  $scope.cityName = $scope.case.court.courtcity;
                  $scope.districtName = $scope.case.court.courtdistict;
                  $scope.courtName = $scope.case.court.courtname;
                }
                //取出除律师的参数并且编辑赋值
                barrister(data.data.caseLawyers);

                // 对方当事人
                $scope.dfdsrList = data.data.caseAdversaryClients;

                for (var i = 0; i < $scope.dfdsrList.length; i++) {
                  $scope.dfdsrList[i].dfdsrtextmm = true;
                  $scope.dfdsrcasetype = $scope.dfdsrList[i].casetype;
                  if ($scope.dfdsrcasetype == 1) {
                    $scope.dfdsrcasetype = '原告';
                  } else {
                    $scope.dfdsrcasetype = '被告';
                  }
                }
                // 当事人
                $scope.dsrList = data.data.caseClients;

                for (var i = 0; i < $scope.dsrList.length; i++) {

                  $scope.dsrList[i].dsrtextmm = true;

                  $scope.dsrcasetype = $scope.dsrList[i].casetype;
                  if ($scope.dsrcasetype == 1) {
                    $scope.dsrcasetype = '原告';
                  } else {
                    $scope.dsrcasetype = '被告';
                  }
                }
              } else {
                alert(data.message);
              }
              $rootScope.loadingShow = false;
              $rootScope.fadeShow = false;
            });

          }
        }
        /* else {
            alert("诉讼请求内容不能为空");
        }*/
    };


    /*案件信息编辑*/
    $scope.editInformationStageShow = function () {

      $scope.editStageShow = true;
      $scope.caseCopy = angular.copy($scope.case);
      $(".form_datetime").datetimepicker({
        minView: "month",
        format: 'yyyy-mm-dd',
        language: "zh-CN",
        charset: "utf-8"
      }).on('changeDate', function (ev) {
        $('.form_datetime').datetimepicker('hide');
      });
    };
    $scope.editInformationStageHide = function () {
      $scope.editStageShow = false;
      $scope.case =  $scope.caseCopy;
    };
    /*诉讼信息编辑*/
    $scope.editIitigationStageShow = function () {
      $scope.editIitigationShow = true;
      $scope.caseLitigation = angular.copy($scope.case);
    };
    $scope.editIitigationStageHide = function () {
      $scope.editIitigationShow = false;
      $scope.case =  $scope.caseLitigation;
    };

    /**
     * 案件信息编辑
     * @param caseName    案件名称
     * @param demand      诉讼请求
     * @param summary     案件描述
     * @param caseBusinessTypeId  业务类型
     * @param entrustedBusinessId  委托事项
     * @param entrustedAmount  委托金额
     * @param foreign          涉外  1 - 是；2 - 否；
     * @param lawSupport       法律援助  1 - 是；2 - 否;
     * @param contractStartDate 合同起始日期
     * @param contractEndDate   合同终止日期
     * @param caseOrigin  案件来源
     * @param tenderingAmount 标的金额
     * @param caseJudgesList 法官列表
     * @param caseJudgesId 法官ID
     * @param caseJudgesName 法官名称
     * */
    var countId = "";
      $scope.editCaseContent = function (type) {
        if($scope.case.caseClassificationId == 1){
          /*诉讼*/
          if(type == 1) {
            /*案件信息*/
            var params = {
              "partition":type,
              "caseName": $scope.case.casename, //案件名称
              "entrustedAmount": $scope.case.entrustedAmount, //委托金额
              "foreign": $scope.case.foreign,  //是否涉外
              "lawSupport": $scope.case.lawSupport, //法律援助
              "caseOrigin": $scope.case.caseOrigin,  //案件来源
              "remark":$scope.case.remark,   //备注
              "caseId":caseId
            };
          }else if(type ==2){
            var sub_judge = '';
            if( $scope.caseJudgesList.length > 0) {
              //这个条件用来解决[【案件详情】添加审理法院后保存，成功后查看未填写] 这个bug。但实际上是因为 法官名字没填写造成的...？
              sub_judge = $scope.caseJudgesList[0].judgename
            }
            if($scope.case.court !=null){
              countId = $scope.case.court.id;
            }
            var params = {
              "partition":type,
              "demand":$scope.case.demand,   //诉讼请求
              "summary":$scope.case.summary,  //案件描述
              "courtId":countId,  //法院
              "tenderingAmount":$scope.case.tenderingAmount, //标的金额
              "caseJudgesName":sub_judge, //法官名称 $scope.caseJudgesList[0].judgename 备注代码有问题 予以修改
              "caseId":caseId
            };
            if(typeof($scope.case.court) == "object"){
            //  params.courtId = $scope.case.court.id;
            }
          }
        }else if($scope.case.caseClassificationId == 2){
          /*非诉讼*/
          var params = {
            "caseName": $scope.case.casename, //案件名称
            "entrustedAmount": $scope.case.entrustedAmount, //委托金额
            "foreign": $scope.case.foreign,  //是否涉外
            "lawSupport": $scope.case.lawSupport, //法律援助
            "caseOrigin": $scope.case.caseOrigin,  //案件来源
            "remark":$scope.case.remark,   //备注
            "caseBusinessTypeId":$scope.case.caseBusinessType.id,   //业务类型
            "entrustedBusinessId":$scope.case.entrustedBusiness.id,  //委托事项
            "caseId":caseId
          };
        }else if($scope.case.caseClassificationId == 3){
        /*法律顾问*/
          var params = {
            "caseName": $scope.case.casename, //案件名称
            "entrustedAmount": $scope.case.entrustedAmount, //委托金额
            "foreign": $scope.case.foreign,  //是否涉外
            "lawSupport": $scope.case.lawSupport, //法律援助
            "caseOrigin": $scope.case.caseOrigin,  //案件来源
            "remark":$scope.case.remark,   //备注
            "caseBusinessTypeId":$scope.case.caseBusinessType.id,   //业务类型
            "contractStartDate":$scope.case.contractStartDate,   //合同起始日期
            "contractEndDate":$scope.case.contractEndDate,   //合同终止日期
            "caseId":caseId
          };
        }else if($scope.case.caseClassificationId == 4){
        /*项目*/
          var params = {
            "caseName": $scope.case.casename, //案件名称
            "entrustedAmount": $scope.case.entrustedAmount, //委托金额
            "foreign": $scope.case.foreign,  //是否涉外
            "lawSupport": $scope.case.lawSupport, //法律援助
            "caseOrigin": $scope.case.caseOrigin,  //案件来源
            "remark":$scope.case.remark,   //备注
            "summary":$scope.case.summary,  //案件描述
            "caseId":caseId
          };
        }
        caseBarDetailxiaService.putCourtAJSS(params).then(function (response) {
          if(response.code === 1){
            $scope.$emit('noticeCaseName', { caseName: $scope.case.casename });
            $scope.editIitigationShow = false;
            $scope.editStageShow = false;
          }
        });
      };

    /*业务类型下拉连动*/
    $scope.caseTrialLevel = function () {
      var params = {
        "firLevelId":$scope.case.caseClassificationId,
        "secLevelId":$scope.case.caseBusinessType.id
      }
      caseBarDetailxiaService.caseTrialLevel(params).then(function (response) {
        if(response.data.code == 1){
          $scope.typeSecList = response.data;
          $scope.case.entrustedBusinessId = $scope.typeSecList.data[0];
        }
      })
    }

    /*案件详情下拉*/
    $scope.assistance = [
      {id:1, name:'是'},
      {id:2, name:'否'}
    ];
    /*查看更多字符串截取*/
    // $scope.intercept = $('.g-intercept').text();
    // console.log('intercept',$scope.intercept);

    /*页面验证*/
    $scope.validateOptions = {
      blurTrig: true,
      showError: false,
      removeError: true
    };


  /*讼诉页面显示 数字转文字*/
    $scope.caseType = function (type) {
      switch (type){
        case 1:
          return "诉讼";
          break;
        case 2:
          return "非诉讼";
          break;
        case 3:
          return "法律顾问";
          break;
        case 4:
          return "项目";
          break;
      }
    };

    /*来源页面显示 数字转文字*/
    $scope.caseSource = function (type) {
      switch (type){
        case 1:
          return "老客户";
          break;
        case 2:
          return "续约";
          break;
        case 3:
          return "自己获取";
          break;
        case 4:
          return "朋友推荐";
          break;
        case 5:
          return "客户推荐";
          break;
        case 6:
          return "同事推荐";
          break;
        case 7:
          return "社会活动";
          break;
        case 8:
          return "网上获取";
          break;
        case 9:
          return "来访咨询";
          break;
        case 10:
          return "其他";
          break;
      }
    };

    /*案件所属页面显示 数字转文字*/
    $scope.caseThe = function (type) {
      if(!type){
        return;
      }
      if(type == 0){
        return "自已办理";
      }else{
        for(var i=0; i<$scope.teamList.length; i++){
          if(type == $scope.teamList[i].id){
            return $scope.teamList[i].teamname;
          }
        }
      }
    };




  // $scope.caseWhether = function (type) {
  //   switch (type){
  //     case 1:
  //       return "是";
  //       break;
  //     case 2:
  //       return "否";
  //       break;
  //   }
  // };

    //律师头像的点击事件
    $("#ZhuLawyer").click(function () {
        caselvshitype = 1;
    });
    $("#AnyuanLawyer").click(function () {

        caselvshitype = 2;
    });

    $("#Zhixinxiezhu").click(function () {
        caselvshitype = 3;

    });


    /**
     * 去除多余的律师
     * @param lawyers
     * @param inx
     */
    function dislodgehostLawyer(lawyers, inx) {

        for (var i = 0; i < lawyers.length; i++) {
            if (lawyers[i].lawyertypeid == inx) {
                lawyers.splice(i, 1);
            }
        }
    }

    $scope.SourcesID = null;

    $(".Sources").show();
    $(".Sources1").hide();

    //律师处理
    function barrister(caseLawyers) {

        /**首先案源律师默认显示加号*/
        for (var i = 0; i < caseLawyers.length; i++) {
            var str = new Object();
            str.id = caseLawyers[i].id;
            str.lawyertypeid = caseLawyers[i].lawyertypeid;
            str.lawyerid = caseLawyers[i].lawyerid;
            lawyersbarrister.push(str);
            //主办律师 只有一个 肯定有
            if (caseLawyers[i].lawyertypeid == 1) {
                $scope.SponsorUsername = caseLawyers[i].lawyer.username;
                //律师成员主键
                $scope.lawyerIdmajor = caseLawyers[i].id;
            } else if (caseLawyers[i].lawyertypeid == 2) { //案源律师 数组接受 可有 可无  有的话只有一个
                $(".Sources1").show();
                $(".Sources").hide();
                $scope.SourcesUsername = caseLawyers[i].lawyer.username;
                $scope.SourcesID = caseLawyers[i].id;
            } else if (caseLawyers[i].lawyertypeid == 3) {  //可以没有 可以有多个
                //noinspection JSAnnotator
                var obk = caseLawyers[i].lawyer;
                obk.id = caseLawyers[i].id;
                CaseLawyersList.push(obk)
            }
        }
        $scope.CaseLawyers = CaseLawyersList
    }

    /**删除案源律师*/
    $scope.Sources = function (name) {
        if ($rootScope.typeIf!=7) {
            caseBarDetailxiaService.deletebarrister($scope.SourcesID, $scope.loginId, "2", caseId, name, $scope.LawyerId, loginName, caseName).then(function (data) {
                if (data.code == 1) {
                    angular.element(".Sources").show();
                    angular.element(".Sources1").hide();
                    //删除了案源律师后 要把关联表律师ID置为空
                    $scope.SourcesID = null;
                    /**刷新页面*/
                    // $scope.getCaseDetails();
                }
                $rootScope.loadingShow = false;
                $rootScope.fadeShow = false;
            }, function (response) {
                $rootScope.loadingShow = false;
                $rootScope.fadeShow = false;
                console.error('updatemessage error', response.status, response.statusText);
            });
            lawyersbarrister = [];
        }

    };

    /**删除协助律师*/
    $scope.Casedeletey = function (id, index, name) {
        ydeletebarrister(id, index, name);
    };


    /**删除协助律师接口*/
    function ydeletebarrister(id, index, name) {
        /*   id	Int	主键ID
         userId	String	用户id
         lawyerType	String	律师身份：0 - 未知；1 - 主办律师；2 - 案源律师；3 - 协助律师；5-其它；
         caseId	String	案件id
         lawyeName	String	律师名称*/

        caseBarDetailxiaService.deletebarrister(id, $scope.loginId, "3", caseId, name, $scope.LawyerId).then(function (data) {
            if (data.code == 1) {

                CaseLawyersList.splice(index, 1);
                $scope.CaseLawyers = CaseLawyersList;
                /**刷新页面*/
                //$scope.getCaseDetails();
            }
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
        }, function (response) {
            /**刷新页面*/
            //   $scope.getCaseDetails();
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            console.error('updatemessage error', response.status, response.statusText);
        });
        lawyersbarrister = [];

    }


    /**修改律师*/
    function modification(name, ybid) {
        var obj = new Object();
        obj.caseId = caseId;
        if (caselvshitype == 1) {
            if ($scope.lawyerIdmajor == 0) {
                obj.id = null
            } else {
                obj.id = $scope.lawyerIdmajor
            }
            obj.lawyerType = 1;
        } else if (caselvshitype == 2) {
            if ($scope.SourcesID == null) {
                obj.id = null
            } else {
                obj.id = $scope.SourcesID
            }
            obj.lawyerType = 2;
        } else if (caselvshitype == 3) {
            obj.lawyerType = 3;
        }
        obj.lawyerId = ybid;
        obj.lawyerName = name;
        obj.userId = $scope.loginId;
        obj.caseName = caseName;
        obj.userName = loginName;
        $scope.casejson = JSON.stringify(obj);

        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;

        //添加案源律师
        caseBarDetailxiaService.modificationbarrister($scope.casejson).then(function (data) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            if (data.code == 1) {

               $scope.mReminderheadline="邀请律师提示";
                //主办律师
                if (caselvshitype == 1) {
                   // $(".ZhuLawyer_img").hide();
                  //  $('.ZhuLawyer_title').hide();
                //    $("#ZhuLawyer").html("<div class='addlvshi' style='background-color: rgb(66,183,159);color:#fff;'><span style='margin-top: 0px;'>" + name + "</span></div><span>主案律师</span>");
                    $scope.mRemindertxt="已给主办律师<font color='red'>"+name+"</font>发送邀请！请耐心等待";
                } else if (caselvshitype == 2) {
                   /* $(".Sources1").show();
                    $(".Sources").hide();

                    $scope.SourcesUsername = name
                    //案源律师ID
                    $scope.SourcesID = data.id*/
                    $scope.mRemindertxt="已给案源律师<font color='red'>"+name+"</font>发送邀请！请耐心等待";
                } else if (caselvshitype == 3) {
                  /*  //协助律师对象
                    var obj = new Object();
                    obj.lawyerid = ybid;
                    obj.username = name;
                    obj.id = data.id;

                    CaseLawyersList.push(obj);

                    $scope.CaseLawyers = CaseLawyersList*/
                    $scope.mRemindertxt="已给协助律师<font color='red'>"+name+"</font>发送邀请！请耐心等待";
                }



            } else {
                 // alert(data.msg);
                 $scope.mRemindertxt=data.msg;
            }
            $("#myBarrister").modal("show");
            lawyersbarrister = [];
            /**刷新页面*/
            // $scope.getCaseDetails();


        }, function (response) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            console.error('updatemessage error', response.status, response.statusText);
        });
    }

    /**
     * 如果是归档案件不可编辑
     */
    $scope.hideArchive = function () {
        if ($stateParams.type == 7||$rootScope.typeIf==7) {
            $scope.type1 = $stateParams.type;
            //TODO:
            /*案件详情*/ //原版$
            angular.element('#btn-add-dsr').hide();//当事人新增按钮
            angular.element('#btn-add-dfdsr').hide();//对方当事人新增按钮
            angular.element("#provinceMenu").addClass("fade");//审理法院-省
            angular.element("#cityMenu").addClass("fade");//审理法院-市
            angular.element("#districtMenu").addClass("fade");//审理法院-地区
            angular.element("#courtMenu").addClass("fade");//审理法院-法院
            angular.element("#btn-commary-edit").hide();//案件概述编辑按钮
            angular.element("#btn-case-decond").hide();//诉讼请求编辑按钮
        }
    };
    // 关注案例列表
    $scope.CorrelationCabe = function (caseId, page, pagesize) {
       $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;
        caseBarDetailxiaService.Attention(caseId, page, pagesize).then(function (data) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            if (data.code == 1) {
                if (data.data.length != 0) {
                    $scope.CabeMyshow = true;
                }

                setCabeListcabe(data.data);
                setPage(data);

            } else {

            }

        }, function (response) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            console.error('updatemessage error', response.status, response.statusText);
        });
    };


    //处理返回的案件
    function setCabeListcabe(data) {
        var AtentionList = [];
        for (var i = 0; i < data.length; i++) {
            AtentionList.push(JSON.parse(data[i].relatiedInfo))
        }
        $scope.correlation = AtentionList


    }

    // 取消收藏 取消关注
    $scope.Enshrine = function (relatedId, relatedName) {
        $scope.relatedStatus = "0";
        //userId：用户id，relatedName：相关案例名称
        caseBarDetailxiaService.Enshrine(relatedId, caseId, $scope.relatedStatus, $scope.loginId, relatedName).then(function (data) {
            if (data.code == 1) {
                $scope.CorrelationCabe(caseId, "1", "4");
            } else {

            }
        }, function (response) {
            console.error('updatemessage error', response.status, response.statusText);
        });


    };

    //跳转详情
    $scope.gocaseBarDeailAnliDetailController = function (id) {
        $state.go("caseBarDetailAnLiDetail3");

        $cookies.put('correlationCABEID', id, {
            expires: expireDate
        });
    };

    $scope.GeneralPage = 0;
    $scope.detailspagination = 1;

    //分页
    //请求完成后设置分页
    function setPage(data) {

        var Pagelist = [];
        for (var i = data.beginPage; i < data.endPage + 1; i++) {
            Pagelist.push(i);
        }
        $scope.GeneralPage = data.totalPage;


        $('.select').css('color', '#666');
        $scope.totalPage = 5; //每页显示数量
        $scope.totalCount = data.totalCount; //总条数 已经ok
        $scope.totalPas = Pagelist;         //分页需要的数组
        $scope.page = $scope.detailspagination;   //当前页

        setTimeout(function () {
            if ($scope.page === 1) {
                $('.select' + ($scope.page)).css('color', 'red');
            } else {
                $('.select' + ( $scope.detailspagination)).css('color', 'red');
            }

        }, 50);
    }

    /*用户点击分页点击改变页码*/
    $scope.changePage = function (currentPage) {
        if (currentPage <= $scope.GeneralPage && currentPage > 0) {
            // totalPage 页码
            $scope.CorrelationCabe(caseId, currentPage, "4");

            //用户改变页码的时候保存下当前页面的下标
            $scope.detailspagination = currentPage;

        } else {
            // console.log('列表页码越界!');
        }
    };


    /**
     * 回车修改相关人员名字
     * @param $event 当前对象
     * @param caseid 案件ID
     * @param id 相关人员ID
     * @param caseclientname 相关人员名称
     * @param status 状态：1-当事人，2-对方当事人，3-审判人员，4-第三人
     */
    $scope.changeDS = function ($event, caseid, id, caseclientname,status,index) {
        var $event = $event.target;
        var e = $($event);
        $(document).keyup(function (event) {
            if (event.keyCode == '13') {
                var mName=$('#dsxia'+id).val();
                $rootScope.loadingShow = true;
                $rootScope.fadeShow = true;
                var caseName = "";
                if(status==1){
                    caseName = mName+$scope.navcasecausename+$scope.navcasebusinessname;
                }else{
                    caseName = "";
                }
                caseBarDetailxiaService.updateCaseRelatedPersonName($scope.loginId, caseid, status, mName, id,caseName).then(function (data) {
                    $rootScope.loadingShow = false;
                    $rootScope.fadeShow = false;
                    if (data.code == 1) {
                        if (status == 1) {//当事人
                            $(e).css('display', 'none');
                            $(e).siblings('#DSXianame').css('display', 'block');
                            $scope.dsrList[index].dsrtextmm=true;
                            if(index==0){
                                caseBarDetailBarService.changeNavName(caseName);
                                $cookies.put('caseAppName',caseName,{
                                    expires: expireDate
                                });
                            }
                        } else if (status == 2) {//对方当事人
                            $(e).css('display', 'none');
                            // $(e).siblings('#DFname').css('display', 'block');
                            $scope.dfdsrList[index].dfdsrtextmm=true;
                        }
                    }
                }, function (response) {
                    $rootScope.loadingShow = false;
                    $rootScope.fadeShow = false;
                    console.error('updateCaseRelatedPersonName error', response.status, response.statusText);
                });
            }
        });
    };


    /**
     * 删除当事人
     * @param id
     * @param caseClientName
     */
    $scope.deleteDsr = function (id, caseClientName, index) {
        if ($rootScope.typeIf!=7) {
            $rootScope.loadingShow = true;
            $rootScope.fadeShow = true;
            var len = $scope.dsrList.length;
            var caseName = "";
            if (len > 1) {
                caseName = $scope.dsrList[1].caseclientname + $scope.navcasecausename + $scope.navcasebusinessname;
                caseBarDetailxiaService.deleteDSR(id, caseId, caseClientName, $scope.loginId, caseName).then(function (data) {
                    $rootScope.loadingShow = false;
                    $rootScope.fadeShow = false;
                    if (data.code == 1) {
                        $scope.getDSRList(caseId);
                        if (index == 0) {
                            caseBarDetailBarService.changeNavName(caseName);
                            $cookies.put('caseAppName', caseName, {
                                expires: expireDate
                            });
                        }
                    }
                });
            } else {
              $rootScope.loadingShow = false;
              $rootScope.fadeShow = false;
              // bootbox.alert({
              //     size: "small",
              //     title: "提示信息",
              //     message: "不能删除当事人",
              //     callback: function () { /* your callback code */
              //     }
              // });
              bootbox.dialog({
                message: "确定删除当事人",
                title: "提示信息",
                buttons: {
                  Cancel: {
                    label: "确定",
                    // className: "btn-default",
                    className: "btn-confirm",
                    // confirmButtonColor: "#DD6B55",
                    callback: function () {

                    }
                  },
                }
              })
            }
        }
    };

    /**
     * 删除对方当事人
     * @param id
     * @param adversaryClientName
     */
    $scope.deleteDFDsr = function (id, adversaryClientName) {
        if ($rootScope.typeIf!=7) {
            bootbox.dialog({
            message: "确定删除当事人",
            title: "提示信息",
            buttons: {
              Cancel: {
                label: "取消",
                // className: "btn-default",
                className: "btn-cancel",
                // confirmButtonColor: "#DD6B55",
                callback: function () {

                }
              },
              OK: {
                label: "确定",
                // className: "btn-primary",
                className: "btn-confirm",
                confirmButtonColor: "#DD6B55",
                callback: function () {
                  caseBarDetailxiaService.deleteDFDSR(id,caseId,adversaryClientName,$scope.loginId).then(function (data) {
                    if (data.code == 1) {
                      $scope.getDFDSRList(caseId);
                    }
                  });
                }
              }
            }
          });

        }
    };

    $(".addlvshi").on("click", function () {
        if ($rootScope.typeIf != 7) {
            $(".LawyerAddBody-xia").removeClass("hide");
        }
    });
   /* $("#AnyuanLawyer").on("click", function () {  // 后期注释
        if ($rootScope.typeIf!=7) {
            $(".LawyerAddBody-xia").removeClass("hide");
        }
    });*/

    $scope.CorrelationCabe(caseId, "1", "4");
    $scope.getCaseDetails();
    $scope.hideArchive();
    //获取对方当事人列表  由于请求接口过多导致结果集混淆，统一从详情取得
    // $scope.getDFDSRList(caseId);
    //获取当事人列表   由于请求接口过多导致结果集混淆，统一从详情取得
    // $scope.getDSRList(caseId);
    $scope.init();

    //案由详情
    $scope.caseBarReason = caseBarReason;
    $scope.caseBarClose = caseBarClose;
    $scope.caseReason = caseReason;

  $scope.caseBarR = {
      caseBarReason:false,
    };
    //案由
  function caseBarReason() {
    $scope.caseBarR.caseBarReason = true;
    caseReason();
  }
  //案由关闭
  function caseBarClose() {
    $scope.caseBarR.caseBarReason = false;
  }

  //案由
  function caseReason() {
    var params = {id: $scope.case.casecauseid};
    caseBarDetailxiaService.caseReason(params).then(function (response) {
      $scope.caseReasonList = response.data.data;
    });
  }


  $scope.saveCasePer = saveCasePer;
  $scope.saveCaseOrganiza = saveCaseOrganiza;
  $scope.selectConsignerDetail = selectConsignerDetail;
  //保存自然人
  function saveCasePer() {
      if($scope.phoneEmpty || $scope.phoneValid ){
          return;
      }
    customerBarService.addZRRCustomer($scope.addNaturalPerCase).then(function (data) {
      if(data.code == 1){
        // var item = {
        //   biglawuserid:data.data.biglawuserid,
        //   contactnumber:data.data.contactnumber,
        //   customerGroupId:data.data.customerGroupId,
        //   id:data.data.id,
        //   caseclientname:data.data.name,
        //   dsrtextmm:data.data.true,
        //   type:1
        // };
        // $scope.dsrList.push(item);
        $('.L_peplAddBox2').addClass('hide');
          $scope.addDSRAppleS($scope.addNaturalPerCase.name);
          $scope.addNaturalPerCase = {};
          $scope.searchPeoInput = '';
      }
    });
  }

  //保存机构
  function saveCaseOrganiza(addOrganizaCaseCase) {
    if($scope.phoneEmpty || $scope.phoneValid ){
      return;
    }
    customerBarService.addFRCustomer(addOrganizaCaseCase).then(function (data) {//addOrganizaCase
      if(data.code==1){
        // var item = {
        //   biglawuserid:data.data.biglawuserid,
        //   id:data.data.id,
        //   companyname:data.data.companyname,
        //   contactname:data.data.contactname,
        //   contactphone:data.data.contactphone,
        //   customerGroupId:data.data.customerGroupId,
        //   type:1
        // };
        // $scope.dsrList.push(item);
        $('.L_peplAddBox2').addClass('hide');
        $scope.addDSRComS($scope.addOrganizaCaseCase.companyname,$scope.addOrganizaCaseCase.id);
        $scope.addOrganizaCaseCase = {};
        $scope.searchCusInput = '';
      }
    })
  }

  $scope.delPer = delPer;
  function delPer(index) {
    $scope.dsrList.splice(index,1);
  };


  //案件所属
  function caseBelongs() {
    customerBarService.caseBelongs().then(function (response) {
      $scope.teamList = response.data.data;
    })
  }

  //从列表选择委托人
  function selectConsignerDetail(natrualPer, type) {
    if (natrualPer == null) {
      return;
    }
    var flag = false;
    for(var i=0;i<$scope.addPerList.length; i++){
      if ($scope.addPerList[i].id == natrualPer.customerpersonId) {
        flag = true;
      }
    }
    var item = {
      id: natrualPer.customerpersonId,
      caseclientname: natrualPer.name,
      caseclienttype : type,
      dsrtextmm: true
    };
    if(!flag){
      //获取当事人列表
      // $scope.getDSRList(caseId);
      $scope.dsrList.push(item);
    }
    $scope.showModule.addModule = false;
    $scope.showModule.searchList = false;
    $scope.searchName.name = '';
  };

  //点击×关闭新建弹框
  $scope.CaseButtonClose = function () {
    $scope.showModule.addModule = false;
  };

  //法人手机号码验证
  $scope.phoneEmpty = false;
  $scope.phoneValid = false;
  $scope.checkMobileNaturalPer = checkMobileNaturalPer;
  $scope.checkMobileOrganiza = checkMobileOrganiza;
  function checkMobileNaturalPer(){
    var phone = $scope.addNaturalPerCase.contactnumber;
    var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(17[0]{1})|(15[0-3]{1})|(15[5-9]{1})|(18[0-9]{1}))+\d{8})$/;
    if(phone == ''){
      $scope.phoneEmpty = true;
    }else if(phone.length !=11){
      $scope.phoneValid = true;
    }else if(!myreg.test(phone)){
      $scope.phoneValid = true;
    }else{
      $scope.phoneEmpty = false;
      $scope.phoneValid = false;
    }
    return false;
  }

  //机构手机号码验证
  function checkMobileOrganiza(){
    var phone = $scope.addOrganizaCaseCase.contactphone;
    var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(17[0]{1})|(15[0-3]{1})|(15[5-9]{1})|(18[0-9]{1}))+\d{8})$/;
    if(phone == ''){
      $scope.phoneEmpty = true;
    }else if(phone.length !=11){
      $scope.phoneValid = true;
    }else if(!myreg.test(phone)){
      $scope.phoneValid = true;
    }else{
      $scope.phoneEmpty = false;
      $scope.phoneValid = false;
    }
    return false;
  }

/* 已归档案件样式设置*/
  /*if($rootScope.typeIf==7){
    console.log($rootScope.typeIf,'datalixia')
   $('#gCaseDataLiEdit').hide()
   $('.gCaseDataLiEdit').hide()
   }*/



  // //清空文本框内容
  // $scope.clearForm = clearForm;
  // function clearForm(form) {
  //   // input清空
  //   $(':input', form).each(function () {
  //     var type = this.type;
  //     var tag = this.tagName.toLowerCase(); // normalize case
  //     if (type == 'text' || type == 'password' || tag == 'textarea')
  //       this.value = "";
  //     // 多选checkboxes清空
  //     // select 下拉框清空
  //     else if (tag == 'select')
  //       this.selectedIndex = -1;
  //   });
  // };
};


